<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>

<div style="margin:20px 0;"></div>
<div class="easyui-panel" >
    <div style="padding:10px 60px 20px 60px">
        <form id="chnServiceCostForm"  name="chnServiceCostForm" method="post" >
            <input type="hidden" id="chn_service_cost_uuid" name="chn_service_cost_uuid" value="${appInfChnServeiceCostEntity.chn_service_cost_uuid}"/>
            <input type="hidden" id="service_uuid" name="service_uuid" value="${appInfChnServeiceCostEntity.service_uuid}"/>
            <input type="hidden" id="service_param_uuid" name="service_param_uuid" value="${appInfChnServeiceCostEntity.service_param_uuid}"/>
            <input type="hidden" id="rec_id" name="rec_id" value="${appInfChnServeiceCostEntity.rec_id}" />
            <input type="hidden"  name="channel_no" value="${appInfChnServeiceCostEntity.channel_no}" />
            <table cellpadding="5" style="width:100%">
                <tr>
                    <td>通道名称:</td>
                    <td><input class="easyui-textbox" type="text" readonly="readonly" id="chnname"  value="${appInfChnServeiceCostEntity.CHANNEL_NM}" data-options="required:true"/>
                    <a href="javascript:void(0)" class="easyui-linkbutton detail-remove" iconCls="icon-search" id="selelctChn">选择</a></td>
                    <input type="hidden" id="channelno" name="channelno" value="${appInfChnServeiceCostEntity.channel_no}" />
                    <td>业务名称:</td>
                    <td><input class="easyui-textbox" type="text" readonly="readonly" id="sername" value="${appInfChnServeiceCostEntity.PARAM_NM}" data-options="required:true"/></td>
                </tr>
                <tr>
                    <td>业务参数名称:</td>
                    <td><input class="easyui-textbox" type="text" name="purname" readonly="readonly" id="purname" data-options="required:true" value="${appInfChnServeiceCostEntity.SERVICE_NM }"></input>
                        <a href="javascript:void(0)" class="easyui-linkbutton detail-remove" iconCls="icon-search" id="selelctsername">选择</a></td>
                    <td>贷记卡附加手续费(元):</td>
                    <td><input class="easyui-numberspinner" type="text" id="credit_attachfee" name="credit_attachfee" data-options="precision:2,decimalSeparator:'.',min:0,max:9999999999.99" value="${appInfChnServeiceCostEntity.CREDIT_ATTACHFEE }"></input></td>
                </tr>
                <tr>
                    <td>贷记卡扣率(万分位):</td>
                    <td><input class="easyui-numberspinner" type="text" id="credit_rate" name="credit_rate" data-options="precision:0,min:0,max:10000" value="${appInfChnServeiceCostEntity.credit_rate }"></input></td>

                    <td>贷记卡最小手续费(元):</td>
                    <td><input class="easyui-numberspinner" type="text" id="credit_minfee" name="credit_minfee" data-options="validType:['checkminamt'],precision:2,decimalSeparator:'.',min:0,max:9999999999.99" value="${appInfChnServeiceCostEntity.credit_minfee }"></input></td>
                </tr>
                <tr>
                    <td>贷记卡最大手续费(元):</td>
                    <td><input class="easyui-numberspinner" type="text" id="credit_maxfee" name="credit_maxfee" data-options="validType:['checkmaxamt'],precision:2,decimalSeparator:'.',min:0,max:9999999999.99" value="${appInfChnServeiceCostEntity.credit_maxfee}"></input></td>
                </tr>
            </table>

            <div style="text-align:center;padding:5px">
                <a href="javascript:void(0)" class="easyui-linkbutton btn detail-remove" iconCls="icon-save" id="saveBtn">保存</a>
                <a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-back" onclick="back()">返回</a>
                    <%--<jiepos:buttonDetailTag menuCode="${menuCode}" formId="chnServiceCostForm"></jiepos:buttonDetailTag>--%>
            </div>
        </form>
    </div>
</div>
<div id="commonTree">
    <div id="ztreeObj" class="ztree"></div>
</div>


<div id="dialogChn">
    <div style="padding:3px" class="easyui-panel datagrid-toolbar">
        <div>
            <span>通道编号:</span>
            <input id="channel_no" type="text" name="channel_no"  class="easyui-textbox"  >
            <a href="#" class="easyui-linkbutton btn"   onclick="chnSearch() ">查询</a>
            <a href="#" class="easyui-linkbutton btn" onclick="resetParam() ">重置</a>
        </div>
    </div>
    <table id="tableChn">
    </table>

</div>


<script>
    $(document).ready(function() {
        $("#dialogChn").attr("style", "display: none;");
        $.extend($.fn.textbox.defaults.rules, {
            checkminamt: {
                validator: function(value){
                    return /^(?=([0-9]{1,10}$|[0-9]{1,10}\.))(0|[1-9][0-9]*)(\.[0-9]{1,2})?$/.test(value);
                },
                message: '最小交易金额格式不符或长度超限'
            },
            checkmaxamt: {
                validator: function(value){
                    return /^(?=([0-9]{1,10}$|[0-9]{1,10}\.))(0|[1-9][0-9]*)(\.[0-9]{1,2})?$/.test(value);
                },
                message: '最大交易金额格式不符或长度超限'
            }
        });
        var commonTree;

        var setting = {
            callback:{
                onClick: zTreeOnClick
            },
            data:{
                simpleData:{enable: true}
            }
        }
        function zTreeOnClick(event, treeId, treeNode) {
            if(treeNode.flag!="p"){
                $.jpmessage.info('只能选择业务参数!');
                return;
            }
        };
        
        /*选择业务参数*/
        $("#selelctsername").click(function(){
            openTree("../serviceInf/getServiceInfTree.do","选择业务参数",serselected,setting);
        })

        
        function serselected(){
            var nodes = commonTree.getSelectedNodes();
            if(nodes && nodes.length > 0){
                $("#service_uuid").val(nodes[0].getParentNode().id);
                $("#service_param_uuid").val(nodes[0].id);
                $("#purname").textbox("setValue", nodes[0].name);
                $("#sername").textbox("setValue", nodes[0].getParentNode().name);
            }
        }
        function hserselected(){
            var nodes = commonTree.getSelectedNodes();
            if(nodes && nodes.length > 0){
                $("#hitch_service_uuid").val(nodes[0].getParentNode().id);
                $("#hitch_service_param_uuid").val(nodes[0].id);
                $("#hpurname").textbox("setValue", nodes[0].name);
                $("#hsername").textbox("setValue", nodes[0].getParentNode().name);
            }
        }

        function chnSearch() {
        	grid.load({
                channel_no: $('#channel_no').val()
            });
        }

        function openTree(url,title,callback,setting){
            $.ajax({
                url: url,
                async: false,
                success: function(result){
                    commonTree=$.fn.zTree.init($("#ztreeObj"), setting, result);
                }
            });
            openModal("#commonTree", {width:400, height:400,title:title}, callback);
        }

        $("#saveBtn").click(function(){
            if($("#chnServiceCostForm").form("validate")){
                if($("#credit_minfee").val() != null && $("#credit_minfee").val() != ""
                    && $("#credit_maxfee").val()!=null && $("#credit_maxfee").val()!=""
                    && $("#credit_maxfee").val() != parseFloat(0)
                    && parseFloat($("#credit_minfee").val()) > parseFloat($("#credit_maxfee").val())){
                    $.jpmessage.info('最小交易金额不应大于最大交易金额');
                    return;
                }
            }
                var options = {
                    type: "post",
                    url:'<c:url value="/chnServiceCost/getServiceUuid.do"/>',
                    success: function (date) {
                        if (date == 'false') {
                            //表单提交的方法、比如ajax提交
                            $("#chnServiceCostForm").attr("action","../chnServiceCost/saveChnServiceCostDetail.do?");
                            document.getElementById("chnServiceCostForm").submit();
                        }else {
                            $.jpmessage.info("此通道已存在业务参数!");
                            return;
                        }
                    },
                    error: function (data) {
                        $.jpmessage.info("保存发生错误");
                    }
                };
                 $("#chnServiceCostForm").ajaxSubmit(options);


        });
        $("body").keydown(function() {
            if (event.keyCode == "13") {//keyCode=13是回车键
                $('#saveBtn').click();
            }
        });
    })
    var grid;
    //通道名称
    $("#selelctChn").click(function(){
    	grid = $("#tableChn").jpgrid({
            url: "../channelinf/getChannelInfListJson.do",
            columns: [
                {title: "通道编号", field: "CHANNEL_NO",width:100},
                {title: "通道名称", field: "CHN_NM"},
                {title: "通道类型", field: "CHN_TP",width:100},
                {title: "通道对应表", field: "CHN_PRMTB"},
                {title: "交易频率", field: "TRANS_INTERVAL",width:80}
            ]
        });
        openModal("#dialogChn", {width:800, height:400,title:"选择通道"}, saveChn);

    })
    function saveChn(){
        return commonsave("tableChn","channel_uuid","chnname","channel_no","dialogChn");
    }
    function commonsave(tableid,id,name,channel_no,dialog){
        var rows = $('#'+tableid).datagrid('getSelections');
        if(rows.length==0){
            $.jpmessage.warning('请至少选择一条记录!');
            return false;
        }
        if(rows.length>1){
            $.jpmessage.warning('只能选择一条记录!');
            return false;
        }

        $("#"+id).val(rows[0].UUID);
        if("chngrpname"==name){
            $("#chngrpname").textbox("setValue", rows[0].CHANNEL_GRP+"-"+rows[0].DESCPT);
        }
        if("chnname"==name){
            $("#chnname").textbox("setValue", rows[0].CHANNEL_NO+"-"+rows[0].CHN_NM);
        }
        if("channel_no"==channel_no){
            $("#channelno").val(rows[0].CHANNEL_NO);
        }
        return;
    }
</script>